package org.imlinker;

import java.io.UnsupportedEncodingException;

import javax.swing.UIManager;

import org.imlinker.core.Core;

/**
 * 启动类，主要作用是获得程序运行的真实路径.
 * 
 * 初始化并启动Core类，初始化并启动Login类。
 */

final class Linker extends Object {

	public static void main(final String[] args) {

		try {
			// 设置系统lookandfeel
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}

		String path = "";

		// 获得imLinker.jar文件所在文件夹
		String linkerClassPath = Linker.class.getResource("").toString();
		String jarName = "Linker.jar";
		if (linkerClassPath.indexOf(jarName) >= 0) {

			// 打包后的情况
			if (System.getProperty("os.name").startsWith("Linux")) {
				path = linkerClassPath;
				path = path.substring(path.indexOf("/"), path.indexOf(jarName));
			} else if (System.getProperty("os.name").startsWith("Windows")) {
				path = linkerClassPath;
				path = path.substring(path.indexOf("file:") + 5, path
						.indexOf(jarName));
			}

			try {
				path = java.net.URLDecoder.decode(path, "utf-8");
			} catch (UnsupportedEncodingException e) {
				System.out.println("decode path to utf-8 failed");
			}

		} else {
			// 编辑代码时的情况
			path = linkerClassPath.substring(linkerClassPath.indexOf("/"),
					linkerClassPath.indexOf("/bin"));
		}

		Core core = new Core(path);
		core.start();

	}
}
